package com.five.wisdomEat.controller;

import cn.hutool.core.date.DateTime;
import com.five.wisdomEat.entity.Comment;
import com.five.wisdomEat.entity.ResponseMessage;
import com.five.wisdomEat.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/comment")
public class CommentController {
    @Autowired
    private CommentService service;

    @GetMapping("/getCommentList")
    public ResponseMessage selectCommentList(){
        return service.selectCommentList();
    }

    @PostMapping("/insertComment")
    public ResponseMessage insertComment(String cContent,String cDNumber){
        Comment comment = new Comment();
        comment.setCContent(cContent);
        comment.setCDNumber(cDNumber);
        comment.setCTime(new DateTime());
        return service.insertComment(comment);
    }

    @PostMapping("/updateComment")
    public ResponseMessage updateComment(Integer id,String cContent,String cDNumber){
        Comment comment = new Comment();
        comment.setId(id);
        comment.setCContent(cContent);
        comment.setCDNumber(cDNumber);
        comment.setCTime(new DateTime());
        return service.updateComment(comment);
    }

    @PostMapping("/deleteComment")
    public ResponseMessage deleteComment(Integer id){
        return service.deleteComment(id);
    }
}
